<template>
	<om-page :title="pageTitle">
		<view class="flex justify-end padding">
			<view v-if="showAll" style="position: fixed;z-index: 10;">
				<text class="lg text-gray cuIcon-attentionfavorfill" @click="showAllClick">隐藏</text>
			</view>
			<view v-else style="position: fixed;z-index: 10;">
				<text class="lg text-gray cuIcon-attentionfavor" @click="showAllClick">全显</text>
			</view>
		</view>
	  <view class="page__bd" style="padding-bottom: 60px;">
	    <om-wing-blank size="default">
	      <uni-list>
	        <view v-for="(item, index) in datas" :key="index">
	          <view v-if="item.h5Path">
				  	<uni-list-item v-show="hasItemVal(item)" class="padding-0"  @click="onTab(item)" >
				  		<view class="tui-flex align-center">
				  			<view class="tui-col-5"><om-label :align="'right'" :label="item.name"></om-label></view>
				  			<view class="tui-col-7">{{item.value}}</view>
				  		</view>
				  	</uni-list-item>
	          </view>
	          <view v-else>
				  <uni-list-item v-show="hasItemVal(item) && item.name != '编码'" class="padding-0"  :showArrow="false">
				  	<view class="tui-flex align-center">
				  		<view class="tui-col-5"><om-label :label="item.name"></om-label></view>
				  		<view class="tui-col-7" v-show="dataType(item.value) == 'string' && item.name != '表单编码'">{{item.value?item.value:''}}</view>
						<view class="tui-col-7" v-show="dataType(item.value) == 'string' && item.name == '表单编码'"><a class="om-color" @click="goForm(item.value)">{{item.value?item.value:''}}</a></view>
						<view class="tui-col-7" v-show="dataType(item.value) == 'arrary'"><button class="bg-blue" size="mini" @click="openFile()">查看</button></view>
				  	</view>
				  </uni-list-item>
	          </view>
	        </view>
	      </uni-list>
	    </om-wing-blank>
	  </view>
	  <om-button :buttons="buttons" @btnChange="btnChange" fontSize="medium"></om-button>
	  <om-hover-button openType="switchTab" title="返回首页" url="/pages/main/main/main"></om-hover-button>
	</om-page>
</template>

<script>
		
	export default {
		data() {
			return {
				cacheKey:"",
				datas: [],
				pageTitle:"",
				buttons:[],
				showAll:false,
				isSign:false,
				storageKey:"signature-key",
				image:"",
				imgHeight:'',
				imgWidth:'',
				itemId: '',
			}
		},
		onLoad(options){
			this.pageTitle = options.title||"详细信息"
			uni.setNavigationBarTitle({
			      title: this.pageTitle
			    })
			let _that = this
			if(options.cacheKey){
				_that.cacheKey = options.cacheKey
				uni.getStorage({
				  key: options.cacheKey,
				  success: function(res) {
					if (res.data) {
					  _that.datas = res.data
					}
				  },
				  fail() {
				  	console.error("获取失败")
				  }
				})
			}else{
				let durl = options.durl;
				if (durl) {
					let _that = this;
					_that.om.request(durl).then(res=>{
						_that.datas = d.value;
					})
				}
			}
			if(options.buttons){
				this.buttons = JSON.parse(options.buttons)
			}
			if(options.itemId){
				this.itemId = options.itemId
			}
		},
		onUnload() {
			uni.removeStorage({
				key:this.cacheKey
			})
		},	
		methods: {
			goForm(fileId){
				let busCode = '';
				for(let i=0; i<this.datas.length; i++){
					if(this.datas[i].name == '编码'){
						busCode = this.datas[i].value
					}
				}
				this.om.getFormInfoByFileCode(fileId, busCode)
			},
			openFile(){
				let _that = this
				if(this.buttons.length>0){
					let itemid = this.buttons[0].link.substring(this.buttons[0].link.indexOf('itemid=')+7,this.buttons[0].link.length)
					uni.navigateTo({
						url: "/pages/public/filetable/filetable?busCode=OBJ0211&mainId=undefined&subId="+ itemid +"&simpleClazzName=undefined"
					})
				}else{
					if(this.itemId){
						uni.navigateTo({
							url: "/pages/public/filetable/filetable?busCode=OBJ0211&mainId=undefined&subId="+ this.itemId +"&simpleClazzName=undefined"
						})
					}else{
						// _that.om.toast('网络异常！');
					}
				}
			},
			dataType(data){
				let dtype = '';
				if(Object.prototype.toString.call(data)==='[object Array]'){
					dtype = 'arrary'
				}else{
					dtype = 'string'
				}
				return dtype;
			},
			showAllClick(){
				this.showAll = !this.showAll
			},
			hasItemVal(item){
				if(!this.showAll){
					if(item.value){
						return true
					}else{
						return false
					}
				}else{
					return true
				}
			},
			onTab(item){
			    if (item.h5Path) {
			      if (item.attr && item.attr.infoShow){
			        uni.setStorage({
			          key: 'cacheAttr',
			          data: item.attr.infoShow
			        })
			      }
			      uni.navigateTo({
			        url: item.h5Path +"?cacheKey=cacheAttr"
			      })
			    }
			 },
			 btnChange(index){
				 var button = this.buttons[index]
				 if(button.link){
					 uni.navigateTo({
					   url: button.link
					 })
				 }
			 }
		}
	}
</script>

<style>

</style>
